import Vue from 'vue';
import VueRouter from 'vue-router'
import DaohangView from '@/daohangView.vue';

// import { component } from 'vue/types/umd';

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/homeView',
    //打开页面就想显示首页
  },
  {
    path: '/',
    name: 'daohang',
    component: DaohangView,
    children: [
      {
        path: 'homeView',
        name: 'homeView',
        component: () => import('../views/HomeView.vue'),
        mata: {
          isShow: true
        },
      },
      {
        path: 'about',
        name: 'about',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue'),
        meta: {
          isShowTab: true
        },
      },
      {
        path: 'huodong',
        name: 'huodong',
        component: () => import(/* webpackChunkName: "about" */ '../views/huodongView.vue'),
        meta: {
          isShowTab: true
        },
      },
      {
        path: 'geren',
        name: 'geren',
        component: () => import(/* webpackChunkName: "about" */ '../views/gerenView.vue'),
        meta: {
          isShowTab: true
        },
      },
    ]
  },

  {
    path: '/recommend',
    name: 'recommend',
    component: () => import(/* webpackChunkName: "day_recommend" */ '../views/recommendView.vue')
  },
  {
    path: '/day_recommend',
    name: 'day_recommend',
    component: () => import(/* webpackChunkName: "day_recommend" */ '../views/day_readView.vue')
  },


  {
    path: '/login',
    name: 'login',
    component: () => import('../views/loginView.vue')
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('../views/registerView.vue')
  },
  {
    path: '/lunbo',
    name: 'lunbo',
    component: () => import('../components/luboView.vue')
  },
  {
    path: '/Read',
    name: 'Read',
    component: () => import('../components/ReadView.vue')
  },
  {
    path: '/tobook',
    name: 'tobook',
    component: () => import('../components/book_View.vue')
  },
  {
    path:'/search',
    name: 'search',
    component: () => import('../views/SearchView.vue')
  }
]

const router = new VueRouter({
  routes
})


export default router;

let originPush = VueRouter.prototype.push;
let originReplace = VueRouter.prototype.replace;
VueRouter.prototype.push = function (location, resolve, reject) {
    // 此函数上下文(this指向)为VueRouter的一个实例
    if (resolve && reject) {    
        //如果我们自己指定了成功/失败的回调，则自己传入
        originPush.call(this, location, resolve, reject)
        //若此时直接使用originPush()，相当于调用了函数originPush()，则函数内的this指向window（内部代码将无法执行）。故应用call或apply方法修改this指向
    } else {    //如果我们没有指定成功/失败的回调，则自动帮我们生成，防止报错
        originPush.call(this, location, () => { }, () => { })
    }
}
// replace方法同理
VueRouter.prototype.replace = function (location, resolve, reject) {
    if (resolve && reject) {
        originReplace.call(this, location, resolve, reject)
    } else {
        originReplace.call(this, location, () => { }, () => { })
    }
}